package com.tr.otel.action;

import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import lombok.Data;

import com.mbsu.core.persistency.domain.UserAccount;
import com.mbsu.core.service.UserAccountService;


@ManagedBean
@RequestScoped
@Data
public class KullaniciAction {
	
	@ManagedProperty(value="#{userAccountService}")
	private UserAccountService kullaniciServis;
	
	private String ad;
	private String soyad;
	private String yas;
	private String ulke;
		
	private boolean kullanicilariGoster;
	private List<UserAccount> kullanicilar;
		
	public void kaydet(ActionEvent ae){
		UserAccount kullanici = new UserAccount();
		kullanici.setName(ad);
		kullanici.setSurname(soyad);
		kullanici.setAge(Integer.parseInt(yas));
		kullanici.setCountry(ulke);
		
		kullaniciServis.save(kullanici);
		
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Yeni kullanıcı: " + ad + soyad + " başarıyla kaydedildi"));
	}
	
	public void kullanicilariGetir(ActionEvent ae){
		kullanicilar = kullaniciServis.listUserAccounts(new UserAccount());
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Toplam " + kullanicilar.size()  + " kayıt bulundu"));
	}
	
}
